static int gusb_intr_in_ep;
static int gusb_bulk_out_ep;
static int gusb_bulk_in_ep;
+static gusb_llops_t libusb_llops;
static usb_dev_handle *udev;
static void garmin_usb_scan(libusb_unit_data *, int);
usb_strerror());
}
}
+
return r;
}
fatal("Claim interfaced failed: %s\n", usb_strerror());
}
+ libusb_llops.max_tx_size = dev->descriptor.bMaxPacketSize0;
for (i = 0; i < dev->config->interface->altsetting->bNumEndpoints; i++) {
struct usb_endpoint_descriptor * ep;
ep = &dev->config->interface->altsetting->endpoint[i];
+
switch (ep->bmAttributes & USB_ENDPOINT_TYPE_MASK) {
#define EA(x) x & USB_ENDPOINT_ADDRESS_MASK
case USB_ENDPOINT_TYPE_BULK:
GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
}
+ /*
+ * Recursion, when used in a disciplined way, can be our friend.
+ *
+ * The Garmin protocol requires that packets that are exactly
+ * a multiple of the max tx size be followed by a zero length
+ * packet. Do that here so we can see it in debugging traces.
+ */
+
+ if (sz && !(sz % gusb_llops->max_tx_size)) {
+ gusb_cmd_send(opkt, 0);
+ }
+
return (rv);
}
gusb_llop_get llop_get_bulk;
gusb_llop_send llop_send;
gusb_llop_close llop_close;
+ int max_tx_size;
} gusb_llops_t;
/* Provided by the common code. */
DWORD rxed = GARMIN_USB_INTERRUPT_DATA_SIZE;
unsigned char *buf = (unsigned char *) &ibuf->dbuf;
int tsz=0;
- unsigned char *obuf = buf;
while (sz) {
/* The driver wrongly (IMO) rejects reads smaller than
WriteFile(usb_handle, obuf, sz, &rsz, NULL);
if (rsz != sz) {
- fatal ("Error sending %d bytes. Successfully sent %d\n", sz, rsz);
- }
-
- if (0 == sz % usb_tx_packet_size) {
- DWORD sz2;
- GPS_Diag("Writing padding buffer.\n");
- WriteFile(usb_handle, 0, 0, &sz2, NULL);
+ fatal ("Error sending %d bytes. Successfully sent %ld\n", sz, rsz);
}
return rsz;
&size, NULL)) {
fatal("Couldn't get USB packet size.\n");
}
+ win_llops.max_tx_size = usb_tx_packet_size;
gusb_syncup();